package com.fyzk.utils;

import android.content.Context;
import android.view.View;

import java.util.List;

import zhy.com.highlight.HighLight;
import zhy.com.highlight.interfaces.HighLightInterface;
import zhy.com.highlight.position.OnBaseCallback;
import zhy.com.highlight.position.OnBottomPosCallback;
import zhy.com.highlight.position.OnLeftPosCallback;
import zhy.com.highlight.position.OnRightPosCallback;
import zhy.com.highlight.position.OnTopPosCallback;
import zhy.com.highlight.shape.RectLightShape;
import zhy.com.highlight.view.HightLightView;

/**
 * Created by fanxs11 on 2017/7/27.
 */

public class GuideUtils {

    private static HighLight mHightLight;

    public static void showGuide(Context context, final List<GuideInfor> lightViewInfors) {
        mHightLight = new HighLight(context);
        mHightLight.autoRemove(false);
        mHightLight.intercept(true);    //拦截属性默认为true 使下方ClickCallback生效
        mHightLight.enableNext();
        mHightLight.setOnLayoutCallback(new HighLightInterface.OnLayoutCallback() {
                    @Override
                    public void onLayouted() {
                        //界面布局完成添加tipview
                        if (mHightLight != null) {

                            if (lightViewInfors != null && lightViewInfors.size() != 0) {
                                for (int i = 0; i < lightViewInfors.size(); i++) {
                                    GuideInfor infor = lightViewInfors.get(i);
                                    OnBaseCallback callback;
                                    switch (infor.position) {
                                        case LEFT_POSITION:
                                            callback = new OnLeftPosCallback(45);
                                            break;
                                        case RIGHT_POSITION:
                                            callback = new OnRightPosCallback(45);
                                            break;
                                        case TOP_POSITION:
                                            callback = new OnTopPosCallback(45);
                                            break;
                                        case BOTTOM_POSITION:
                                            callback = new OnBottomPosCallback(45);
                                            break;
                                        default:
                                            callback = new OnLeftPosCallback(45);
                                            break;
                                    }
                                    if (infor.shape == null) {
                                        infor.shape = new RectLightShape(0,0,0,30,30);
                                    }
                                    mHightLight.addHighLight(infor.viewId, infor.showLayout, callback, infor.shape);
                                }
                                //然后显示高亮布局
                                mHightLight.show();
                            }
                        }
                    }
                })
                .setClickCallback(new HighLight.OnClickCallback() {
                    @Override
                    public void onClick() {
//                        AppToast.getToast().show("clicked and show next tip view by yourself");
//                        mHightLight.next();
                    }
                }).setOnNextCallback(new HighLightInterface.OnNextCallback() {
                    @Override
                    public void onNext(HightLightView hightLightView, View targetView, View tipView) {
//                        AppToast.getToast().show("clicked next");
                    }
                });
    }

    public static void onGuideClick(View view) {
        switch (view.getId()) {
//            case R.id.guide_next_iv:
//                if(mHightLight.isShowing() && mHightLight.isNext()) {   //如果开启next模式
//                    mHightLight.next();
//                } else {
//                    mHightLight.remove();
//                }
//                break;
//            case R.id.guide_known_iv:
//                mHightLight.remove();
//                break;
        }
    }

    public static final int LEFT_POSITION = 0;
    public static final int TOP_POSITION = 1;
    public static final int RIGHT_POSITION = 2;
    public static final int BOTTOM_POSITION = 3;
}
